{extend name="platform/base" /} 
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style>
.right-indent:after{
	content:'';
	display:inline-block;
	width:40%;
}
.order-list td{
	border-right:1px solid #E3E3E3;
}
</style>
{/block} 
{block name="main"}
<div class="row padder-v">
	<div class="col-sm-1"></div>
	<div class="col-sm-2">
		<div class="input-group">
			<input type="text" id="startDate" class="input-sm form-control"
				placeholder="请选择订单开始时间" onclick="WdatePicker()" />
		</div>
	</div>
	<div class="col-sm-2">
		<div class="input-group">
			<input type="text" id="endDate" placeholder="请选择订单结束时间"
				class="input-sm form-control" onclick="WdatePicker()" />
		</div>
	</div>
	<div class="col-sm-2">
		<div class="input-group">
			<input id="userName" class="input-sm form-control" type="text"
				value="" placeholder="请输入收货人姓名">
		</div>
	</div>
	<div class="col-sm-2">
		<div class="input-group">
			<input id="orderNo" class="input-sm form-control" type="text" value="" placeholder="请输入订单编号">
		</div>
	</div>
	<div class="col-sm-2">
		<div class="input-group">
			<select id="order_status"
				class="input-sm form-control input-s-sm inline">
				<option value="">订单状态</option>
				<option value="">全部</option>
				{volist name="order_status_list" id="status"}
				<option value="{$status.status_id}">{$status.status_name}</option>
				{/volist}
			</select>
		</div>
	</div>
	<div class="col-sm-1">
		<div class="input-group">
			<span class="input-group-btn">
				<button class="btn btn-sm btn-default" type="button"
					onclick="LoadingInfo(1)">搜索</button>
			</span>
		</div>
	</div>
</div>
<section class="panel panel-default">
	<div class="table-responsive">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col style="width: 3%;">
				<col style="width: 14%;">
				<col style="width: 10%;">
				<col style="width: 14%;">
				<col style="width: 14%;">
				<col style="width: 13%;">
				<col style="width: 16%;">
				<col style="width: 16%;">
			</colgroup>
			<thead>
				<tr>
					<th class="center"><label> <input type="checkbox"></label></th>
					<th>订单号</th>
					<th class="right">订单金额</th>
					<th class="center">订单状态</th>
					<th class="right right-indent">佣金</th>
					<th>买家</th>
					<th class="center">创建时间</th>
					<th class="center">完成时间</th>
				</tr>
			</thead>
			<tbody id="list">
				<tr></tr>
			</tbody>
		</table>
	</div>
	{include file="platform/page" /}
</section>
{/block} {block name="script"}
<script type="text/javascript">	
	//查询
	$(function(){
	LoadingInfo(1);
});
	//加载数据
	function LoadingInfo(pageIndex) {
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var user_name = $("#userName").val();
		var order_no = $("#orderNo").val();
		var order_status = $("#order_status").val();
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/Commission/commissionDistributionList')}",
			async : true,
			data : {
				"pageIndex" : pageIndex, "start_date" : start_date, "end_date" : end_date, "user_name":user_name, "order_no":order_no, "order_status" : order_status
			},
			success : function(data) {
				//console.log(data);
				var html = '';
				$("#total_count_num").text(data["total_count"]);
				$("#page_count_num").text(data["page_count"]);
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						
						html += '<tr data-show ="1"style="cursor:pointer;" onclick=showOrHideAccordion("accordiondata'+i+'",this);>';
						html += '<td align="center"><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data["data"][i]["order_id"] +'" ></label></div></td>';
						html += '<td>' + data["data"][i]["order_no"] + '</td>';
						html += '<td align="right">' + data["data"][i]["order_money"] + '</td>';
						html += '<td align="center">' + data["data"][i]["status_name"] + '</td>';
						html += '<td align="right" class="right-indent">' + data["data"][i]["commission_money"] + '</td>';
						html += '<td>' + data["data"][i]["user_name"] + '</td>';
						html += '<td align="center">' + timeStampTurnTime(data["data"][i]["create_time"]) + '</td>';
						html += '<td align="center">' + timeStampTurnTime(data["data"][i]["finish_time"]) + '</td>';
						html += '</tr>';
						html +='<tr class="collapse" style="display:none;" id="accordiondata'+i+'">';
						html +='<td colspan="8" style="padding:10px;background-color:#E0E0E0;" >';	
						html +='<table class="table order-list" ><colgroup>';
						html +='<col style="width: 35%;">';
						html +='<col style="width: 15%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 12%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 8%;">';			
						html +='</colgroup>';					
						html +='<tbody>';

						//html +="<tr><td  colspan='8' style='border-left: 1px solid transparent;height:10px;padding:0px;border-right: 1px solid transparent;'></td></tr>";
						html += '<tr class="title-tr">';
						html += '<td>商品</td>';
						html += '<td>商品清单</td>';
						html += '<td>商品利润</td>';
						html += '<td>商品分销比率</td>';
						html += '<td>推广员佣金比例</td>';
						html += '<td>佣金金额</td>';
						html += '<td>收益人</td>';
						html += '</tr>';
						
						
						//循环订单项
						for(var j = 0; j < data["data"][i]["order_item_list"].length; j++){
							var commission_distribution_item = data["data"][i]["order_item_list"][j]["commission_distribution_list"];
							var row = 1;
							if(commission_distribution_item.length >0){
								row = commission_distribution_item.length+1
							}
							html += '<tr calss="no-rightborder"><td style="border-right:0;"rowspan="'+row+'">';
							html += '<div class="product-img"><img src="'+__IMG(data["data"][i]["order_item_list"][j]["picture"]['pic_cover_micro'])+'"></div>';
							html += '<div class="product-infor">';
							html += '<a class="name" href="APP_MAIN/Goods/goodsDetail?id='+data["data"][i]["order_item_list"][j]["goods_id"]+'" target="_blank">'+data["data"][i]["order_item_list"][j]["goods_name"]+'</a>';
							html += '<p class="specification"><span>'+data["data"][i]["order_item_list"][j]["sku_name"]+'</span></p></div>';
							html += '</div></td>';
							html += '<td style="border-left:1px solid #E3E3E3 ;border-right:1px solid #E3E3E3;"rowspan="'+row+'">';//商品信息与商品清单的分割线
							//html += '<div class="cell" style="display: inline-block;"><span>'+data["data"][i]["order_item_list"][t]["goods_name"]+'</span></div>';
							html += '<div class="cell" style="display: inline-block;"><span>'+data["data"][i]["order_item_list"][j]["price"]+'元</span></div>';
							html += '<div class="cell" style="display: inline-block;float:right">'+data["data"][i]["order_item_list"][j]["num"]+'件</div>';
							if(data["data"][i]["order_item_list"][j]['adjust_money'] != 0){
								html += '<div class="cell" style="display: inline-block;"><span>(调价：'+data["data"][i]["order_item_list"][j]["adjust_money"]+'元)</span></div>';
							}
// 							if((data["data"][i]["order_item_list"][j]['refund_status'] != 0) && (data["data"][i]["order_item_list"][j]['refund_operation'] != ''))
							if(commission_distribution_item.length >0){
								for(t = 0; t< commission_distribution_item.length;t++){
									html +='</tr>';
									html +='<tr calss="no-rightborder">';
									html +='<td>'+parseFloat(commission_distribution_item[t]["goods_return"]).toFixed(2)+'</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["goods_commission_rate"]).toFixed(2)+'%</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["commission_rate"]).toFixed(2)+'%</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["commission_money"]).toFixed(2)+'</td>';
									html +='<td>'+commission_distribution_item[t]["promoter_shop_name"]+'('+'姓名:'+commission_distribution_item[t]["realname"]+'<br/>'+'编号:'+commission_distribution_item[t]["promoter_no"]+')'+'</td>';
								}	
							}else{
								html +='<td>0.00</td>';
								html +='<td>0.00%</td>';	
								html +='<td>0.00%</td>';
								html +='<td>0.00</td>';	
								html +='<td></td>';	
							}					
							html += '</tr>';							
						}						
						html +='</tbody></table>';
						html +='</td>';
						html +='</tr>'					
					}
				} else {
					html += '<tr><td colspan="8" align="center">暂无符合条件的数据记录</td></tr>';
				}
				
				$("#list").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
			}
		});
	}	
	//全选
	function CheckAll(event){
		var checked = event.checked;
		$(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
	}
	
	function showOrHideAccordion(accordion_id,event){		
		if($(event).data("show") == 1){			
			$(event).data("show",0);
			$('#'+accordion_id).show();
		}else{
			$(event).data("show",1);
			$('#'+accordion_id).hide();
		} 	
		
	}
	
</script>
{/block}
